
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
	int no,id,val;
}a[150001];
bool cmp(node a,node b)
{
	if(a.val==b.val)return a.no<b.no;
	else return a.val>b.val;
}
int main()
{
	freopen("test.in","r",stdin);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].id,&a[i].val);
		a[i].no=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		printf("%d %d\n",a[i].id,a[i].val);
	return 0;
}
	
